package com.roc.goc.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;

@Configuration
public class CorsConfig {

    @Bean
    CorsWebFilter corsWebFilter(){

        CorsConfiguration corsCofig = new CorsConfiguration();
        corsCofig.addAllowedHeader("*");
        corsCofig.addAllowedMethod("*");
        corsCofig.addAllowedOriginPattern("*");
        corsCofig.setAllowCredentials(true);

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", corsCofig);
        return new CorsWebFilter(source);
    }
}
